/*! \file VertexBufferImpl.cpp
 *	\brief 
 *
 *	created:	2010/12/12
 *	created:	12:12:2010   23:40
 *	filename: 	C:\src\tactics-engine\libs\gd_dx11\VertexBufferImpl.cpp
 *	file path:	C:\src\tactics-engine\libs\gd_dx11
 *	file base:	VertexBufferImpl
 *	file ext:	cpp
 *	author:		Vitalii Trubchaninov
 *				venngraydog@gmail.com
 */
#include "gd_dx11/stdafx.h"
#include "gd_dx11/VertexBufferImpl.h"

#include "gd_dx11/DeviceContext.h"

namespace tt{
namespace gd_dx11{

VertexBufferImpl::VertexBufferImpl()
: m_vertexSize(0)
{

}

VertexBufferImpl::~VertexBufferImpl()
{

}

Result VertexBufferImpl::Create( Device* device, const gd::VertexFormat& format, UInt vertexCount )
{
	m_vertexSize = format.vertexSize();
	UInt dataSize = m_vertexSize * vertexCount;
	return doCreate(device, D3D11_BIND_VERTEX_BUFFER, dataSize);
}

void VertexBufferImpl::onApply( gd::DeviceContext* deviceContext )
{
	DeviceContext* dx11DeviceContext = getDx11Context(deviceContext);
	UInt strides[] = {m_vertexSize};
	UInt offsets[] = {0};
	ID3D11Buffer* buffers[] = {buffer().get()};
	dx11DeviceContext->d3dContext()->IASetVertexBuffers(0, 1, buffers, strides, offsets);
}

} //namespace gd_dx11
} //namespace tt